﻿@model IEnumerable<CmsAdminWorkflowDraftModel>
           
@functions 
{
    string DisplayNullableDates(DateTime? date)
    {
        return date.HasValue ?
            date.Value.ToString("dd/MM/yyyy") :
            string.Empty;
    }
}

@(Html.CmsGrid<CmsAdminWorkflowDraftModel>(Model, new { @class = "t-grid" }).Wrapper("DraftItemGrid")
    .Columns(
            columns =>
            {
                columns.HeaderCssClass("t-grid-header").Bound().Width(40).Title("Content title").HtmlAttributes(new { @class = "t-header" });
                columns.Bound().Title("Type").HtmlAttributes(new { @class = "t-header" });
                columns.Bound().Title("Approval date").HtmlAttributes(new { @class = "t-header" });
                columns.Bound().Title("").HtmlAttributes(new { @class = "t-header" });
                columns.Bound().Width(40).Title("").HtmlAttributes(new { @class = "t-header" });
                columns.Bound().Width(40).Title("").HtmlAttributes(new { @class = "t-header" });
            })
    .Rows(
        rows =>
        {
            rows.Bound().RowItemTemplate(
                @<text>
                <a href="@Url.Action("edit", "cmspage", new { id = item.Id })">@item.Title</a>
                </text>
                );
            rows.Bound().RowItemTemplate(
                @<text>
                <span>@item.EntityType</span>
                </text>
                ).HtmlAttributes(new { @class = "text-center" });
            rows.Bound().RowItemTemplate(
                @<text>
                <span>@DisplayNullableDates(item.ApprovalDate)</span>
                </text>
                ).HtmlAttributes(new { @class = "text-center" });           
            rows.Bound().RowItemTemplate(
                @<text>
                <span>@item.Id</span>
                </text>
                );
            rows.Bound().RowItemTemplate(
                @<text>
                     <a class="b-icon b-icon_delete" title="Page" href="@Url.Action("delete", "cmspage", new {id = item.Id})">Delete</a>
                 </text>
                );
            rows.Bound().RowItemTemplate(
                @<text>
                     <input type="checkbox" name="itemselected" data-entitytype="@item.EntityType" value="@item.Id"/>
                </text>
                ).HtmlAttributes(new { @class = "t-last" });
        })
    .Render()
      )
      

    
@if (Model.Any())
{
    Html.RenderPartial("MassActionsPanel",
                       new MassActionsPanelModel()
                           {
                               GridId = "DraftItemGrid",
                               Actions = new[]
                                             {
                                                 new MassActionModel() {Title = "Send to approval", JsHandler = "massActions.StartWorkflow"},
                                                 new MassActionModel() {Title = "Delete", JsHandler = "massActions.Delete"}
                                             }
                           }
        );
}
